package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.XcxUser;
import com.ruoyi.system.service.IXcxUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "小程序账户")
@RestController
@RequestMapping("/xcxuser")
public class XcxUserController extends BaseController {
    @Autowired
    private IXcxUserService xcxUserService;


    //微信绑定
    @PostMapping("/wxbindXcxUser")
    AjaxResult wxbindXcxUser(@RequestBody XcxUser xcxUser) {
        return xcxUserService.wxbindXcxUser(xcxUser);
    }

    /**
     * 查询小程序账户列表
     */
    @RequiresPermissions("system:xcxuser:list")
    @GetMapping("/list")
    public TableDataInfo list(XcxUser xcxUser) {
        startPage();
        List<XcxUser> list = xcxUserService.selectXcxUserList(xcxUser);
        return getDataTable(list);
    }

    /**
     * 导出小程序账户列表
     */
    @RequiresPermissions("system:xcxuser:export")
    @Log(title = "小程序账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XcxUser xcxUser) {
        List<XcxUser> list = xcxUserService.selectXcxUserList(xcxUser);
        ExcelUtil<XcxUser> util = new ExcelUtil<XcxUser>(XcxUser.class);
        util.exportExcel(response, list, "小程序账户数据");
    }

    /**
     * 获取小程序账户详细信息
     */
    @RequiresPermissions("system:xcxuser:query")
    @GetMapping(value = "/{xcxUserId}")
    public AjaxResult getInfo(@PathVariable("xcxUserId") Long xcxUserId) {
        return success(xcxUserService.selectXcxUserByXcxUserId(xcxUserId));
    }

    /**
     * 新增小程序账户
     */
    @RequiresPermissions("system:xcxuser:add")
    @Log(title = "小程序账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XcxUser xcxUser) {
        return toAjax(xcxUserService.insertXcxUser(xcxUser));
    }

    /**
     * 修改小程序账户
     */
//    @RequiresPermissions("system:xcxuser:edit")
    @Log(title = "小程序账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XcxUser xcxUser) {
        return toAjax(xcxUserService.updateXcxUser(xcxUser));
    }

    /**
     * 删除小程序账户
     */
    @RequiresPermissions("system:xcxuser:remove")
    @Log(title = "小程序账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{xcxUserIds}")
    public AjaxResult remove(@PathVariable Long[] xcxUserIds) {
        return toAjax(xcxUserService.deleteXcxUserByXcxUserIds(xcxUserIds));
    }
}